package net.huashitong.ssydt.provider.msg.service;


import net.huashitong.ssydt.base.dao.LongMapper;
import net.huashitong.ssydt.base.service.AbstractLongService;
import net.huashitong.ssydt.msg.entity.SsMsgMessage;
import net.huashitong.ssydt.msg.entity.vo.MessageInVO;
import net.huashitong.ssydt.msg.entity.vo.MessageOutVO;
import net.huashitong.ssydt.provider.msg.mapper.SsMsgMessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.11.14
 */
@Service
@Transactional
public class SsMsgMessageServiceImpl extends AbstractLongService<SsMsgMessage> implements SsMsgMessageService {

    private SsMsgMessageMapper mapper;

    @Autowired
    public SsMsgMessageServiceImpl(SsMsgMessageMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    protected LongMapper<SsMsgMessage> getLongMapper() {
        return mapper;
    }

    @Override
    public List<SsMsgMessage> findUnReadGroupSendMessage(MessageInVO messageInVO) {
        return mapper.findUnReadGroupSendMessage(messageInVO);
    }

    @Override
    public List<MessageOutVO> findUnReadMessage(MessageInVO messageInVO) {
        if (messageInVO.getLastTime() != null) {
            messageInVO.setLastDateTime(new Date(messageInVO.getLastTime()));
        }
        List<SsMsgMessage> ssMsgMessages = this.mapper.findUnReadMessage(messageInVO);
        List<MessageOutVO> list = new ArrayList<>();
        for (SsMsgMessage ssMsgMessage : ssMsgMessages) {
            list.add(new MessageOutVO(ssMsgMessage));
        }
        return list;
    }
}
